package com.clss.commandhelper.tools;

import android.app.Activity;

import java.util.LinkedList;
import java.util.List;

/**
 * 维护activity静态链表
 * Created by liuv on 2017/6/30.
 */

public class ActivityTracker {
    private final static List<Activity> sActivities = new LinkedList<Activity>();

    public final static void onCreate(Activity activity) {
        if (activity == null) {
            throw new IllegalArgumentException("Activity instance is null");
        }
        sActivities.add(activity);
    }

    public final static void onDestory(Activity activity) {
        if (activity == null) {
            throw new IllegalArgumentException("Activity instance is null");
        }
        sActivities.remove(activity);
    }

    public final static void finishAll() {
        for (Activity activity : sActivities) {
            if (activity.getParent() != null) {
                activity.getParent().finish();
            }
            activity.finish();
        }
        sActivities.clear();
    }
}
